﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace LoLTimers
{

    public partial class FrmMain : Form
    {
        #region FormMovementDllImportsAndConsts
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;

        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();
        #endregion

        private bool isTimersHidden = false;
        private bool isTimersTransparent = true;

        public FrmMain()
        {
            InitializeComponent();

            lblTitle.Text += " V." + Application.ProductVersion;

            try
            {
                string line;
                System.IO.StreamReader file = new System.IO.StreamReader(@"Readme.txt");
                while ((line = file.ReadLine()) != null)
                {
                    txtAbout.Text += line.Replace("\t", "  ") + Environment.NewLine;
                }

                file.Close();
            }
            catch(Exception ex)
            {
                //File does not exists
                txtAbout.Text = @"Welcome to LoL Timers V." + Application.ProductVersion + Environment.NewLine +
                                Environment.NewLine +
                                "This is a small app that lets you keep track of the most important creep camp cooldowns." +
                                Environment.NewLine + Environment.NewLine +
                                "It has been made for personal and non-comercial use only under GNU license (http://www.opensource.org/licenses/GPL-3.0) by Christian Schubert 2012!";
            }

        }

        private void lblMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        private void lblExit_Click(object sender, EventArgs e)
        {
            TimerManager.Instance.StopTimers();
            if (MessageBox.Show("Are you sure you wish to quit LoLTimers?", "Exit", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                TimerManager.Instance.KillKeyboardHook();
                Application.Exit();
            }
            else
            {
                TimerManager.Instance.StartTimers();
            }
        }

        private void lblMinimize_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void glblHideTimers_Click(object sender, EventArgs e)
        {
            if (!isTimersHidden)
            {
                glblHideTimers.GlowColor = Color.IndianRed;
                TimerManager.Instance.HideTimers();
            }
            else
            {
                glblHideTimers.GlowColor = Color.LawnGreen;
                TimerManager.Instance.ShowTimers();
            }

            isTimersHidden = !isTimersHidden;
        }
    }
}
